﻿Imports System.Net.Mail
Imports System.Configuration

Public Class MAIL
    Public Shared Sub SendMail(ByRef rp As DotNetResponse.SQLPersistence, ByVal Destinatario As String, ByVal Clave As String)
        Try
            Dim Mail As MailMessage
            Dim SmtpServer As New SmtpClient()
            SmtpServer.Credentials = New Net.NetworkCredential("Usuario", "Clave") 'WebConfig
            SmtpServer.Port = 25
            SmtpServer.Host = ConfigurationManager.AppSettings("servidor_envio_clave_mail")
            SmtpServer.EnableSsl = True
            Mail = New MailMessage()
            Try
                Mail.From = New MailAddress("Mail de Origen", "Nombre de Origen", System.Text.Encoding.UTF8) 'WebConfig
                'Mail.Subject = Archivo
                'If Archivo.Length > 0 Then
                '    Dim item As New System.Net.Mail.Attachment(Archivo)
                '    Mail.Attachments.Add(item)
                'End If
                Mail.To.Add(Destinatario)
                Mail.Body = "Su Clave de Acceso es :" & Clave 'Web.config

                SmtpServer.Send(Mail)
            Catch ex As Exception
                rp.Errores = True
                rp.MensajeError = ex.Message
            End Try

        Catch ex As Exception
            rp.Errores = True
            rp.MensajeError = ex.Message
        End Try
    End Sub


    Public Shared Sub SendMailErrorApplication(ByVal mensaje As String)
        Try


            Dim Mail As MailMessage
            Dim SmtpServer As New SmtpClient()
            SmtpServer.Credentials = New Net.NetworkCredential("jnquintanilla@gmail.com", "jennifer@2010")
            SmtpServer.Port = 587
            SmtpServer.Host = "smtp.gmail.com"
            SmtpServer.EnableSsl = True
            Mail = New MailMessage()
            Try
                Mail.From = New MailAddress("ErrorAPPLICATION@application.cl", "ERROR", System.Text.Encoding.UTF8)
                Mail.Subject = "ERROR Application"            
                Mail.To.Add("jnquintanilla@gmail.com")

                Mail.Body = mensaje
                SmtpServer.Send(Mail)
            Catch ex As Exception

            End Try

        Catch ex As Exception

        End Try
    End Sub


End Class
